/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * opcionesBusqueda.java
 *
 * Created on 07/05/2011, 06:57:07
 */

package gui;

import javax.swing.JOptionPane;

/**
 *
 * @author Mauricio
 */
public class opcionesBusqueda extends javax.swing.JDialog {

    public boolean volvi; //BANDERA QUE INDICA QUE PRESIONAMOS EL BOTON VOLVER
    public boolean negros; //BANDERA CN. true: CN MANUAL, false: CN ALEATORIO.
    public boolean blancos; //BANDERA CB. true: CB MANUAL. false: CB ALEATORIO.
    public int cantidadBlancos; //VARIABLE QUE ALMACENA LA CANTIDAD DE BLANCOS INGRESADOS EN EL TEXTFIELD

    /** Creates new form opcionesBusqueda */
    public opcionesBusqueda(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setResizable(false); //NO PERMITIR MAXIMIZAR O MINIMIZAR LA VENTANA
        this.setLocationRelativeTo(null); //SITUAR LA VENTANA EN EL CENTRO
        this.volvi = false;
        this.textCantidad.setEnabled(false);
    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        boxBlancos = new javax.swing.JComboBox();
        textCantidad = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        boxNegros = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configuración de Parámetros del Tablero de Ajedrez");

        jLabel3.setText("Caballos Blancos:");

        jLabel2.setText("Caballo Negro:");

        jLabel1.setText("Seleccione la forma de ubicar los caballos:");

        boxBlancos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "Manual", "Autogenerado" }));
        boxBlancos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxBlancosActionPerformed(evt);
            }
        });

        textCantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textCantidadActionPerformed(evt);
            }
        });

        jLabel4.setText("Cantidad:");

        boxNegros.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "Manual", "Autogenerado" }));
        boxNegros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxNegrosActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/iconos/volver.png"))); // NOI18N
        jButton1.setText("Volver");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/iconos/ok.png"))); // NOI18N
        jButton2.setText("Listo");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(boxNegros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(boxBlancos, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(16, 16, 16)
                        .addComponent(jLabel4)
                        .addGap(10, 10, 10)
                        .addComponent(textCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(67, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(189, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jButton1)
                .addGap(16, 16, 16))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(boxNegros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(textCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(boxBlancos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void boxBlancosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxBlancosActionPerformed
        // TODO add your handling code here:

        //BLANCOS ALEATORIOS
        if(boxBlancos.getSelectedIndex()==2){
            textCantidad.setEnabled(true);
            setBlancos(false);
        }
        //BLANCOS MANUALES
        if(boxBlancos.getSelectedIndex()==1){
            textCantidad.setEnabled(false);
            setBlancos(true);

        }

    }//GEN-LAST:event_boxBlancosActionPerformed

    private void textCantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textCantidadActionPerformed
        //NO SE QUE HACIA ESTE METODO
        if((Integer.parseInt(this.textCantidad.getText())<1)||(Integer.parseInt(this.textCantidad.getText())>63)){
            JOptionPane.showMessageDialog(null, "Ingrese un número entre 1 y 63");
        }
}//GEN-LAST:event_textCantidadActionPerformed

    private void boxNegrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxNegrosActionPerformed
        
        //CABALLO NEGRO MANUAL
        if(this.boxNegros.getSelectedIndex()==1){
            setNegros(true);

        }
        //CABALLO NEGRO ALEATORIO
        if(this.boxNegros.getSelectedIndex()==2){
            setNegros(false);
        }

    }//GEN-LAST:event_boxNegrosActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.volvi = true;
        this.dispose();
        //PONEMOS A true PARA INDICAR QUE SALIMOS DE LA VENTANA POR "VOLVI"
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if((this.boxBlancos.getSelectedIndex()==0)||(this.boxNegros.getSelectedIndex()==0)){
            JOptionPane.showMessageDialog(null, "Debe seleccionar alguna de las opciones para los caballos");
            // MENSAJE DE ERROR EN EL CASO DE OLVIDARSE DE SELECCIONAR EN LOS COMBOBOX
        }else{
                if(this.isBlancos()==false){
                //TRATAMIENTO ALEATORIO DE LOS CABALLOS BLANCOS
                if(this.textCantidad.getText().isEmpty()){
                        JOptionPane.showMessageDialog(null, "Falta ingresar la cantidad de caballos blancos");
                }else{
                    if(this.isNegros()){
                    //CB ALEATORIO Y CN MANUAL
                        if((Integer.parseInt(this.textCantidad.getText())<1)||(Integer.parseInt(this.textCantidad.getText()))>63){
                            JOptionPane.showMessageDialog(null, "Error. La cantidad de caballos blancos debe estar entre 1 y 63");
                        }else{
                        this.setCantidadBlancos(Integer.parseInt(this.textCantidad.getText()));
                        this.dispose();
                        JOptionPane.showMessageDialog(null, "Haga click en el cuadro donde desea colocar el caballo negro");

                        }
                        
                    }else{
                    //CB ALEATORIO Y CN ALEATORIO PERO CON CANTIDAD DE CB DEFINIDA
                        if((Integer.parseInt(this.textCantidad.getText())<1)||(Integer.parseInt(this.textCantidad.getText()))>63){
                            JOptionPane.showMessageDialog(null, "Error. La cantidad de caballos blancos debe estar entre 1 y 63");
                        }else{
                        this.setCantidadBlancos(Integer.parseInt(this.textCantidad.getText()));
                        this.dispose();
                        }

                    }
                }
            }else{
                //TRATAMIENTO MANUAL DE LOS CABALLOS BLANCOS
                this.dispose();


                if(this.isNegros()==false){
                    //TRATAMIENTO ALEATORIO DEL CABALLO NEGRO
                    if(this.isBlancos()){
                        //tratamiento manual
                        this.dispose();
                        JOptionPane.showMessageDialog(null, "Ubique los caballos blancos");
                    }else{

                    }
                }else{
                    //TRATAMIENTO MANUAL DEL CABALLO NEGRO
                    JOptionPane.showMessageDialog(null, "Haga click en el cuadro donde desea colocar el caballo negro");
                }
            }
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                opcionesBusqueda dialog = new opcionesBusqueda(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxBlancos;
    private javax.swing.JComboBox boxNegros;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField textCantidad;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the negros
     */
    public boolean isNegros() {
        return negros;
    }

    /**
     * @param negros the negros to set
     */
    public void setNegros(boolean negros) {
        this.negros = negros;
    }

    /**
     * @return the blancos
     */
    public boolean isBlancos() {
        return blancos;
    }

    /**
     * @param blancos the blancos to set
     */
    public void setBlancos(boolean blancos) {
        this.blancos = blancos;
    }

    /**
     * @return the cantidadBlancos
     */
    public int getCantidadBlancos() {
        return cantidadBlancos;
    }

    /**
     * @param cantidadBlancos the cantidadBlancos to set
     */
    public void setCantidadBlancos(int cantidadBlancos) {
        this.cantidadBlancos = cantidadBlancos;
    }

    /**
     * @return the volvi
     */
    public boolean isVolvi() {
        return volvi;
    }

    /**
     * @param volvi the volvi to set
     */
    public void setVolvi(boolean volvi) {
        this.volvi = volvi;
    }

}
